#include "map.h"

namespace QinChat{
    namespace Core{
        template <typename K, typename D>
        CMapNode<K, D>::CMapNode():m_key(K()), m_data(D()){

        }

        template <typename K, typename D>
        CMapNode<K, D>::CMapNode(const K& strType, const D& data):m_key(m_key), m_data(m_data){

        }

        template <typename K, typename D>
        CMapNode<K, D>::CMapNode(const CMapNode<K, D>& other):m_key(other.m_key), m_data(other.m_data){
        }

        template <typename K, typename D>
        bool CMapNode<K, D>::operator< (const CMapNode<K, D>& other){
            if (m_key < other.m_key){
                return true;
            }

            return false;
        }

        template <typename K, typename D>
        bool CMapNode<K, D>::operator> (const CMapNode<K, D>& other){
            if (m_key > other.m_key){
                return true;
            }

            return false;
        }

        template <typename K, typename D>
        bool CMapNode<K, D>::operator== (const CMapNode<K, D>& other){
            if (m_key == other.m_key){
                return true;
            }

            return false;
        }

        template <typename K, typename D>
        CMapNode<K, D>& CMapNode<K, D>::operator= (const CMapNode<K, D>& other){
            if (this == &other){
                return *this;
            }
            m_key = other.m_key;
            m_data = other.m_data;

            return *this;
        }

        template <typename K, typename D>
        bool CMap<K, D>::IsContains(const K& key){
            CMapNode<K, D> sreach(key, D());
            return nullptr != m_rbtree.SearchNode(sreach);
        }

        template <typename K, typename D>
        bool CMap<K, D>::Insert(const K& key, const D& data){
            CMapNode<K, D> insert(key, D());
            return m_rbtree.Insert(insert);
        }

        template <typename K, typename D>
        bool CMap<K, D>::Find(const K& key, D& data){
            CMapNode<K, D> findNode(key, D());
            RBTreeNode<CMapNode<K, D> >* pNode = m_rbtree.SearchNode(findNode);
            if (nullptr == pNode){
                return false;
            }
            else{
                data = pNode->data.GetData();
                return true;
            }
        }
    }
}